#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""
@author: JoeyZhou
@Tool: PyCharm
@Date: 2020/2/19 12:15 AM
@desc: 获取目录下最新的文件
"""
import os
from os import path


class GetNewestFile:
    def get_newest_report(self):
        """
        获得最新的测试报告
        :return:
        """
        parent_path = path.dirname(path.dirname(__file__))  # 获得当前目录的父级目录
        reports_path = parent_path + "/reports/"
        a = os.listdir(reports_path)
        datanames = sorted(a, reverse=True)
        list = []
        for dataname in datanames:
            if os.path.splitext(dataname)[1] == '.html':  # 目录下包含.html的文件
                list.append(dataname)
        print(list)
        print(list[0])
        reports_path = reports_path + list[0]
        print(reports_path)
        return reports_path


if __name__ == '__main__':
    new_report = GetNewestFile()
    new_report.get_newest_report()